<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="供应商" prop="buySupplier">
        <el-select v-model="queryParams.buySupplier" placeholder="供应商" clearable>
          <el-option
            v-for="buySupplier in buySupplierList"
            :key="buySupplier.sId"
            :label="buySupplier.sName"
            :value="buySupplier.sId"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="申请人" prop="lister">
        <el-input
          v-model="queryParams.lister"
          placeholder="请输入申请人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="multiple"
          @click="handleUpdate1"
        >审核通过
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleUpdate2"
        >审核不通过
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="reciptList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="单据ID" align="center" prop="rId" width="100"/>
      <el-table-column label="单据号" align="center" prop="reciptNum" width="100"/>
      <el-table-column
        label="供应商"
        align="center"
        prop="supplierName"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="采购批发总额"
        align="center"
        prop="rpTotals"
        :show-overflow-tooltip="true"
      />
      <el-table-column label="状态" align="center" prop="status" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.drug_process_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column
        label="申请人"
        align="center"
        prop="lister"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="入库操作人"
        align="center"
        prop="updateBy"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="入库时间"
        align="center"
        prop="updateTime"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        :formatter="formatDate"
        :show-overflow-tooltip="true"
      />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
    import {listSupplier} from "@/api/drug/recipt";
    import {listReciptToProcess,updateStatus1,updateStatus2} from "@/api/drug/process";
    export default {
        name: "Notice",
        dicts: ['drug_process_status'],
        data() {
            return {
                // 遮罩层
                loading: true,
                // 选中数组
                ids: [],
                // 非单个禁用
                single: true,
                // 非多个禁用
                multiple: true,
                // 显示搜索条件
                showSearch: true,
                // 总条数
                total: 0,
                buySupplierList: [],
                reciptList: [],
                // 弹出层标题
                title: "",
                // 是否显示弹出层
                open: false,
                // 查询参数
                queryParams: {
                    pageNum: 1,
                    pageSize: 10,
                    buySupplier: undefined,
                    lister: undefined
                },
                // 表单参数
                form: {},
                // 表单校验
                rules: {

                }
            };
        },
        created() {
            this.getSupplierList();
            this.getList();
        },
        methods: {
            getList(){
                this.loading = true;
                listReciptToProcess(this.queryParams).then(response => {
                    this.reciptList = response.rows;
                    this.total = response.total;
                    this.loading = false;
                });
            },
            getSupplierList() {
                this.loading = true;
                listSupplier().then(response => {
                    this.buySupplierList = response.data;
                    this.loading = false;
                });
            },
            // 取消按钮
            cancel() {
                this.open = false;
                this.reset();
            },
            // 表单重置
            reset() {
                this.form = {
                    buySupplier: undefined,
                    lister: undefined
                };
                this.resetForm("form");
            },
            /** 搜索按钮操作 */
            handleQuery() {
                this.queryParams.pageNum = 1;
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.resetForm("queryForm");
                this.handleQuery();
            },
            // 多选框选中数据
            handleSelectionChange(selection) {
                this.ids = selection.map(item => item.rId)
                this.single = selection.length != 1
                this.multiple = !selection.length
            },
            /** 修改按钮操作 */
            handleUpdate1(row) {
                this.reset();
                const rIds = row.rId || this.ids
                this.open = true;
                updateStatus1(rIds).then(response => {
                    this.form = response.data;
                    this.open = true;
                    this.getList();
                    this.$modal.msgSuccess("审核完成");
                    this.title = "单据审核";
                });
            },
            handleUpdate2(row) {
                this.reset();
                const rIds = row.rId || this.ids
                this.open = true;
                updateStatus2(rIds).then(response => {
                    console.log(response.data);
                    this.form = response.data;
                    this.open = true;
                    this.$modal.msgSuccess("审核完成");
                    this.getList();
                    this.title = "单据审核";
                });
            }
        }
    };
</script>
